package com.jml.config;


import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;

@Configuration
public class ErrorPageConfig {

	@Bean
	public EmbeddedServletContainerCustomizer containerCustomizer(){
		return new EmbeddedServletContainerCustomizer() {
			@Override
			public void customize(ConfigurableEmbeddedServletContainer Containers) {
				//默认在static目录下
				ClassPathResource classPathResource = new ClassPathResource("test.txt");
				ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST,"/error-400.html");
				ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND,"/error-404.html");
				ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/error-500.html");
				Containers.addErrorPages(errorPage400,errorPage404,errorPage500);
			}
		};
	}

}
